// pages/fullview/fullview.js
var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();
var wxAuthFail = true;
var inviteuid = 0;
var uid;
Page({

  /**
   * 页面的初始数据
   */
  data: {

    util: util,
    host: util.api_host,
    weburl: '', 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    inviteuid = options.inviteuid ? options.inviteuid : '';
    console.log('inviteuid', inviteuid)
    var fullview=options.fullview||'';
    console.log("urlhost:", that.data.host)
    console.log("options:", options)
    if(fullview){
      that.setData({
        fullview: fullview,
        weburl: that.data.host + options.fullview
      })
    }

    console.log("url:", that.data.weburl)
    that.getLoginInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var invUid = this.data.uid ? this.data.uid : '';
    // var linkcode = this.data.data.linkcode ? this.data.data.linkcode : linkcode;

    var path = '/pages/mine/mine?inviteuid=' + invUid;
    console.log("分享给好友：" + path);

    return {
      title: '',
      path: path
    };
  },
  //重新读取 登录用户信息
  reGetUserInfo: function (e) {
    var that = this;
    console.log("reGetUserInfo: ", e);
    if (e == 1) {
      that.getLoginInfo();
    }
  },
  getLoginInfo: function () {
    var that = this;
    app.LoginUserInfo(function (res) {
      if (res && res != -1) {

        //更新数据
        wxAuthFail = false;
        uid = res.uid;
        that.setData({
          uid: res.uid,
          token: res.token,
          loginUname: res.uname,
          openid: res.wxsmall_openid
        })
      } else {
        wxAuthFail = true;
      }
    }, inviteuid)
  },
})